package ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.contacto;

import model.Aplicacion.Agenda;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;

import simulaPersistencia.CiudadHome;
import ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.apliccion.ContactoDatProvider;
import clasesPrincipales.Ciudad;
import clasesPrincipales.Contacto;

public class BuscarContactoPage extends Panel{

	private static final long serialVersionUID = 4135162034567813281L;
	
		
	public BuscarContactoPage(String id) {
				
		super(id, new CompoundPropertyModel<Contacto>(
				Agenda.getHome(Contacto.class).createExample()));
		Form<Contacto> form = new Form<Contacto>("contactoBusquedaForm");

        form.add(new Label("lbl_cont","CONTACTOS:"));
        form.add(new Label("lbl_nombre","Nombre"));
        form.add(new TextField<String>("nombre"));
        form.add(new Label("lbl_telefono","Telefono"));
        form.add(new TextField<String>("telefono"));
        form.add(new Label("lbl_mail","Mail"));
        form.add(new TextField<String>("mail"));
        form.add(new Label("lbl_ciudad","Ciudad"));
/*Combo*/form.add(new DropDownChoice("ciudad", ((CiudadHome) Agenda.getHome(Ciudad.class)).buscarTodos()));

        //GRILLA
        final ContactoDatProvider provider =new ContactoDatProvider();
        final GuardaGrillaContactoPanel grilla = new GuardaGrillaContactoPanel("guardaGrillaContacto", provider);
        grilla.setOutputMarkupId(true);
        this.add(grilla);
        //BOTON
        form.add(new AjaxSubmitLink("botonBuscarContacto") { 
			private static final long serialVersionUID = 1L;
			@Override
			protected void onSubmit(AjaxRequestTarget arg0, Form<?> form) {
				provider.buscar((Contacto)BuscarContactoPage.this.getDefaultModelObject());
				arg0.addComponent(grilla);
			}
			
			@Override
			protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
				// TODO Auto-generated method stub
				
			}
			
			
			
		});
		this.add(form);
	}


	

}
